package com.example.a79273.shandianban.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a79273.shandianban.R;
import com.example.a79273.shandianban.config.NetconfigYouHuo;
import com.example.a79273.shandianban.model.ShopGuessLikeBean;
import org.xutils.image.ImageOptions;
import org.xutils.x;
import java.util.List;

/**
 * Created by lenovo on 2016/9/1.
 */
public class ShopLikeAdapter extends BaseAdapter {
    private List<ShopGuessLikeBean.DataBean.ListsBean> mData;
    private Context mContext;
    private ImageOptions mOptions;

    public ShopLikeAdapter(List<ShopGuessLikeBean.DataBean.ListsBean> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
        mOptions = new ImageOptions.Builder().setUseMemCache(true)
                .setLoadingDrawableId(R.mipmap.loading23)
                .setFailureDrawableId(R.mipmap.loading23)
                .setSize(230,200).build();
    }

    @Override
    public int getCount() {
        return mData == null?0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoler holder = null;
        if(convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.shop_guesslike_item,null);
            holder = new ViewHoler(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHoler) convertView.getTag();
        }
        ShopGuessLikeBean.DataBean.ListsBean listsBean = mData.get(position);
        holder.mTextViewName.setText(listsBean.getName());
        String price = listsBean.getPrice()+"";
        holder.mTextViewPrice.setText("￥"+price);
        //Picasso.with(mContext).load(NetconfigYouHuo.PIN_JIE+listsBean.getUrl()).placeholder(R.mipmap.loading23).into(holder.mImageViewImg);
        x.image().bind(holder.mImageViewImg,NetconfigYouHuo.PIN_JIE+listsBean.getUrl(),mOptions);
        return convertView;
    }
    static class ViewHoler{
        private ImageView mImageViewImg;
        private TextView mTextViewPrice,mTextViewName;
        public ViewHoler(View view) {
            mImageViewImg = (ImageView) view.findViewById(R.id.iv_guesslike_item_img);
            mTextViewPrice = (TextView) view.findViewById(R.id.tv_guesslike_item_price);
            mTextViewName = (TextView) view.findViewById(R.id.tv_guesslike_item_name);
        }
    }
}
